PACKAGE WL6 - ENFORCE STAFF LUNCH CAP + AUTO CLOSE WORKING LUNCH

Purpose
- Enforce that working lunch credit can never exceed the staff member's configured lunch duration.
- Auto-close open working lunches after the staff member's configured lunch duration.
- Use staff Payroll / Lunch Rules as the source of truth.

Files
- /api/wl6-lunch-common.php
- /api/lunch-start.php
- /api/lunch-end.php
- /api/lunch-status.php
- /cron/auto-close-working-lunch.php
- /sql/verify-wl6-lunch-cap.sql
- /README-WL6.txt

Extract inside
- /home/uent/public_html

Core business rule
- Staff setup lunch time is the maximum working lunch credit.
- 60 min setup + 10 min working lunch = 10 credited, 50 deducted.
- 60 min setup + 90 min working lunch = 60 credited, 0 deducted.
- 30 min setup + 45 min working lunch = 30 credited, 0 deducted.
- 0 min setup = working lunch cannot start.

What changed
1) lunch-start.php
   - Finds the staff member's active payroll/lunch rule.
   - Snapshots lunch_minutes into work_session_breaks.rule_minutes_snapshot.
   - Blocks starting working lunch if lunch_minutes is 0.
   - Blocks multiple working lunch records in the same work session.

2) lunch-end.php
   - Calculates elapsed minutes.
   - Stores actual_minutes as capped working lunch minutes.
   - actual_minutes can never exceed rule_minutes_snapshot.
   - deducted_minutes = rule_minutes_snapshot - capped working lunch minutes.

3) auto-close-working-lunch.php
   - Closes open working lunch records once they reach their cap.
   - Sets deduction_mode = AUTO_CLOSED.
   - Sets ended_at = started_at + rule_minutes_snapshot minutes.
   - Sets actual_minutes = rule_minutes_snapshot.
   - Sets deducted_minutes = 0.

Cron setup
Recommended every 5 minutes:

php /home/uent/public_html/cron/auto-close-working-lunch.php

If you already have a cron calling auto-close-sessions.php, keep it for sessions.
Add this new cron separately for working lunch auto-close.

Testing
1. Staff with 60 min rule:
   - Clock in.
   - Start Working Lunch.
   - End after 5 minutes.
   - Check work_session_breaks: actual_minutes should be 5, deducted_minutes should be 55.

2. Staff with 30 min rule:
   - Start Working Lunch.
   - Wait longer than 30 minutes or manually adjust started_at for testing.
   - Run cron:
     php /home/uent/public_html/cron/auto-close-working-lunch.php
   - Check work_session_breaks: actual_minutes 30, deducted_minutes 0, deduction_mode AUTO_CLOSED.

Verification SQL
Run:
/sql/verify-wl6-lunch-cap.sql

Important
- This package overwrites:
  /api/lunch-start.php
  /api/lunch-end.php
  /api/lunch-status.php
- It does not change the database schema.
- It uses existing work_session_breaks fields.
